

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<script type="text/javascript" src="/agent/js/jquery.1.9.1.js" ></script>
<link href="https://res.wx.qq.com/open/libs/weui/1.1.2/weui-for-work.min.css" rel="stylesheet" >
<script type="text/javascript" src="/pdf/js/jSignature.min.noconflict.js"></script>
<script type="text/javascript" src="/agent/js/layer.js"></script>
    <link rel="stylesheet" type="text/css" href="/agent/css/layer.css" />
<title>手写签名</title>
</head>
<style>
*{padding: 0;margin: 0;font-size: 14px;}
body{padding: 30px;}
#signature{ 
  width: 100%;height: 200px;border: 1px solid #969696;margin: 10px 0px;
  border-radius: 5px;
}  
.weui-btn-area{
  margin: 0 auto;
  margin-top: 65%;
  overflow: hidden;
  width: 90%;
}
.weui-btn-area a{
  display: block;width: 42%;
  font-size: 16px;
  float: left;
  /*margin-left: 12%;*/
  height: 40px;
  line-height: 40px;
}
#showPicker{
  background-color: #de0b10;
  color: #fff;
  margin-top: 0;
  margin-left: 16%;
}
#chongzhi{
  border: 1px solid #de0b10;
  color: #de0b10;
  background-color: #fff;
  margin-top: 0;
}
.jSignature{
  width: 100%!important;
}
</style>

<body ontouchstart="">
<p style="font-size: 16px;color: #333;">手写签名</p>
<div id="signature"></div>  
<div class="weui-btn-area">
    <a href="javascript:;" class="weui-btn weui-btn_primary" id="chongzhi">重置</a>
    <a href="javascript:;" class="weui-btn weui-btn_primary" id="showPicker">提交</a>
</div>
<div id="image" style="margin:20px"></div>
  <script type="text/javascript">
  $(function(){
      //初始化插件
      var dHeight = "200px";
      var dWidth = document.body.scrollWidth ;

      $("#signature").jSignature({height:dHeight,width:dWidth});//初始化调整手写屏大小

  });
   $("#showPicker").click(function(){
         var $sigdiv = $("#signature");
          var datapair = $sigdiv.jSignature("getData")
          console.log(datapair);
          var index = layer.open({type: 2});
           $.ajax({
            type: 'post',
            url:"/index/pdf/upload" ,
            data:{file:datapair},
            success: function(data){
             if(data.code ==  0){
                console.log(data);
                  layer.open({
                    content:data.msg,
                    skin: 'msg',
                    time: 2 //2秒后自动关闭
                });
              }else{
                var url = data.data;
                  //添加禁止标签
                 $('#showPicker').attr("disabled","disabled");
                 $('#chongzhi').attr("disabled","disabled");
                  //提交表单
                  $.ajax({
                    type: 'post',
                    url:"/index/pdfadmin/handwriting/ids/{$ids}" , 
                    data:{sign_url:url},
                    success: function(data){
                      console.log(data);
                      if(data.code == 0){
                         layer.close(index);
                        $('.dotm_btn1').attr("disabled","");
                              layer.open({
                                content: data.msg,
                                skin: 'msg',
                                time: 2,
                              });
                              return false;
                           }else{
                            layer.close(index);
                              window.location.href="/index/pdfadmin/question_success/ids/{$ids}"; 
                           }

                    }
                  });
                 
              }
             
            }
          });
  });  
   $("#chongzhi").click(function(){
          var $sigdiv = $("#signature");
      $sigdiv.jSignature("reset");
      $("#image img").remove();
  });

</script>

</body>
</html>